package com.example.teaching_server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 班级信息数据传输对象
 *
 * @author Teaching Server
 * @since 1.0.0
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "班级详细信息")
public class ClassDTO {

    @NotNull(message = "班级ID不能为空")
    @Schema(description = "班级唯一标识", example = "1")
    private Long classId;

    @NotBlank(message = "班级名称不能为空")
    @Size(max = 50, message = "班级名称长度不能超过50个字符")
    @Schema(description = "班级名称", example = "一班")
    private String className;

    @NotBlank(message = "年级不能为空")
    @Size(max = 20, message = "年级长度不能超过20个字符")
    @Schema(description = "年级", example = "一年级")
    private String gradeLevel;

    @Size(max = 50, message = "班主任姓名长度不能超过50个字符")
    @Schema(description = "班主任姓名", example = "张老师")
    private String headTeacher;

    @Min(value = 0, message = "学生人数不能为负数")
    @Schema(description = "班级学生总数", example = "40")
    private Integer studentCount;

    /**
     * 获取班级显示名称
     *
     * @return 组合显示名称
     */
    @Schema(description = "班级完整显示名称", accessMode = Schema.AccessMode.READ_ONLY)
    public String getDisplayName() {
        if (gradeLevel == null || className == null) {
            return null;
        }
        return gradeLevel + className;
    }

    /**
     * 获取班级编码（用于排序和标识）
     *
     * @return 班级编码
     */
    @Schema(description = "班级编码", accessMode = Schema.AccessMode.READ_ONLY)
    public String getClassCode() {
        if (gradeLevel == null || className == null) {
            return null;
        }
        // 示例：一年级一班 -> 1-1
        String gradeNum = gradeLevel.replaceAll("[^0-9]", "");
        String classNum = className.replaceAll("[^0-9]", "");
        return (gradeNum.isEmpty() ? "0" : gradeNum) + "-" + (classNum.isEmpty() ? "0" : classNum);
    }
}
